package com.ruoyi.equipment.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.DeviceFaultRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.equipment.service.IDeviceFaultRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备故障记录Controller
 * 
 * @author ruoyi
 * @date 2021-03-26
 */
@RestController
@RequestMapping("/fault")
public class DeviceFaultRecordController extends BaseController
{
    @Autowired
    private IDeviceFaultRecordService deviceFaultRecordService;

    /**
     * 查询设备故障记录列表
     */
    @PreAuthorize(hasPermi = "equipment:fault:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceFaultRecord deviceFaultRecord)
    {
        startPage();
        List<DeviceFaultRecord> list = deviceFaultRecordService.selectDeviceFaultRecordList(deviceFaultRecord);
        return getDataTable(list);
    }

    /**
     * 导出设备故障记录列表
     */
    @PreAuthorize(hasPermi = "equipment:fault:export")
    @Log(title = "设备故障记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceFaultRecord deviceFaultRecord) throws IOException
    {
        List<DeviceFaultRecord> list = deviceFaultRecordService.selectDeviceFaultRecordList(deviceFaultRecord);
        ExcelUtil<DeviceFaultRecord> util = new ExcelUtil<DeviceFaultRecord>(DeviceFaultRecord.class);
        util.exportExcel(response, list, "fault");
    }

    /**
     * 获取设备故障记录详细信息
     */
    @PreAuthorize(hasPermi = "equipment:fault:query")
    @GetMapping(value = "/{recordid}")
    public AjaxResult getInfo(@PathVariable("recordid") Long recordid)
    {
        return AjaxResult.success(deviceFaultRecordService.selectDeviceFaultRecordById(recordid));
    }

    /**
     * 新增设备故障记录
     */
    @PreAuthorize(hasPermi = "equipment:fault:add")
    @Log(title = "设备故障记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceFaultRecord deviceFaultRecord)
    {
        return toAjax(deviceFaultRecordService.insertDeviceFaultRecord(deviceFaultRecord));
    }

    /**
     * 修改设备故障记录
     */
    @PreAuthorize(hasPermi = "equipment:fault:edit")
    @Log(title = "设备故障记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceFaultRecord deviceFaultRecord)
    {
        return toAjax(deviceFaultRecordService.updateDeviceFaultRecord(deviceFaultRecord));
    }

    /**
     * 删除设备故障记录
     */
    @PreAuthorize(hasPermi = "equipment:fault:remove")
    @Log(title = "设备故障记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordids}")
    public AjaxResult remove(@PathVariable Long[] recordids)
    {
        return toAjax(deviceFaultRecordService.deleteDeviceFaultRecordByIds(recordids));
    }
}
